<html>
	<body>
 
<form method="post" action="query.php">
<textarea name="query" rows=10 cols=60></TEXTAREA><input type="submit" value="Submit">
</form> 

<?php
	$db_connection = mysql_connect("localhost", "cs143", "");

	mysql_select_db("CS143", $db_connection);

	$query = $_POST["query"];

	$result = mysql_query($query, $db_connection) or die(mysql_error());

	$cols = mysql_num_fields($result);

	print "<table border=\"1\"><tr>";

	$i = 0;
	while ($i < $cols) {
		$header = mysql_field_name($result, $i);
		print "<td>$header</td>";
		$i = $i + 1;
	}
	print "</tr>";

	while($row = mysql_fetch_array($result, MYSQL_NUM)) {
		$k = 0;
		print "<tr>";
		while($k < $cols) {
			$cell = $row[$k];
			print "<td>$cell</td>";
			$k = $k + 1;
		}
		print "</tr>";
	}
	print "</table>";


	mysql_close($db_connection);
?>
 
</body>
</html> 
